using System;
using Moq;
using NUnit.Framework;
using System.Threading;

namespace Fines.Powershell.PowershellMSBuildTask.Tests
{
    [TestFixture]
    public class PowershellHostTest
    {
        private Mock<IPowershellTask> powershellTaskMock;
        private PowershellHost host;

        [SetUp]
        public void SetUp()
        {
            this.powershellTaskMock = new Mock<IPowershellTask>();
            this.host = new PowershellHost( this.powershellTaskMock.Object );
        }

        [TearDown]
        public void TearDown()
        {
        }

        [Test]
        public void SetShouldExit()
        {
            this.host.SetShouldExit( 42 );

            this.powershellTaskMock.VerifySet( t => t.ShouldExit = true );
            this.powershellTaskMock.VerifySet( t => t.ExitCode = 42);
        }

        [Test]
        public void CurrentCulture()
        {
            Assert.AreEqual( Thread.CurrentThread.CurrentCulture, this.host.CurrentCulture );
        }

        [Test]
        public void CurrentUICulture()
        {
            Assert.AreEqual( Thread.CurrentThread.CurrentUICulture, this.host.CurrentUICulture );
        }

        [Test]
        public void Name()
        {
            Assert.AreEqual( typeof( PowershellHost ).Name, this.host.Name );
        }

        [Test]
        public void Version()
        {
            Assert.AreEqual( new Version( 1, 0, 0, 0 ), this.host.Version );
        }

        [Test]
        public void InstanceId()
        {
            Assert.AreNotEqual( Guid.Empty, this.host.InstanceId );
        }

        [Test]
        [ExpectedException(typeof(NotImplementedException))]
        public void EnterNestedPrompt()
        {
            this.host.EnterNestedPrompt();
        }

        [Test]
        [ExpectedException( typeof( NotImplementedException ) )]
        public void ExitNestedPrompt()
        {
            this.host.ExitNestedPrompt();
        }

        [Test]
        public void NotifyBeginApplication()
        {
            this.host.NotifyBeginApplication();
        }

        [Test]
        public void NotifyEndApplication()
        {
            this.host.NotifyEndApplication();
        }

        [Test]
        public void UI()
        {
            Assert.IsTrue( typeof( PowershellHostUI ).IsAssignableFrom(this.host.UI.GetType()) );
        }

    }
}
